package com.szl.yeb.controller;


import com.szl.yeb.common.constant.MsgConstant;
import com.szl.yeb.entity.Salary;
import com.szl.yeb.common.R;
import com.szl.yeb.service.SalaryService;
import com.szl.yeb.utils.ResponseProcessor;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDate;

/**
 * (Salary)表控制层
 *
 * @author szl
 * @since 2022-08-24 16:21:29
 */
@Api(tags = "工资账套管理接口(SalaryController)")
@RestController
@RequestMapping("/salary/sob")
public class SalaryController {

    @Autowired
    private SalaryService salaryService;

    @ApiOperation("获取所有工资账套")
    @GetMapping("/")
    public R<Object> getSalaries(){
        return R.obj(salaryService.list());
    }

    @ApiOperation("添加工资账套")
    @PostMapping("/")
    public R<Object> addSalary(@RequestBody Salary salary){
        salary.setCreateDate(LocalDate.now());
        return ResponseProcessor.getResWithMsg(salaryService.save(salary), MsgConstant.ADD);
    }

    @ApiOperation("更新工资账套")
    @PutMapping("/")
    public R<Object> updateSalary(@RequestBody Salary salary){
        return ResponseProcessor.getResWithMsg(salaryService.updateById(salary), MsgConstant.UPDATE);
    }

    @ApiOperation("删除工资账套")
    @DeleteMapping("/{id}")
    public R<Object> deleteSalary(@PathVariable Integer id){
        return ResponseProcessor.getResWithMsg(salaryService.removeById(id), MsgConstant.DELETE);
    }

}

